home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / dsp / dspkgctr.z / dspkgctr / gcc / sdbout.c < prev    next >
C/C++ Source or Header  |  1992-06-08  |  38KB  |  1,437 lines

  1. /* Output sdb-format symbol table information from GNU compiler.
  2.    Copyright (C) 1988 Free Software Foundation, Inc.
  3.  
  4.    $Id: sdbout.c,v 1.16 92/04/22 10:48:39 pete Exp $
  5.  
  6. This file is part of GNU CC.
  7.  
  8. GNU CC is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 1, or (at your option)
  11. any later version.
  12.  
  13. GNU CC is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with GNU CC; see the file COPYING.  If not, write to
  20. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  22.  
  23. #include "config.h"
  24.  
  25. #ifdef SDB_DEBUGGING_INFO
  26.  
  27. #include "tree.h"
  28. #include "rtl.h"
  29. #include <stdio.h>
  30. #if defined( DSP56000 ) || defined( DSP96000 )
  31. /*    Defines for "special" symbols   */
  32.  
  33. enum memory_map
  34. {
  35.     memory_map_p, 
  36.     memory_map_x,
  37.     memory_map_y,
  38.     memory_map_l,
  39.     memory_map_none,
  40.     memory_map_error=666666
  41. };
  42.  
  43. union addr_map
  44. {
  45.     enum memory_map mape;
  46.     long l;
  47.     unsigned long u;
  48. };
  49.  
  50. struct core_addr_struct
  51. {
  52.     union addr_map w0;
  53.     union addr_map w1;
  54. };
  55.  
  56. typedef struct core_addr_struct CORE_ADDR;
  57.  
  58.  
  59. #define _ETEXT    "etext"
  60. #define _EDATA    "edata"
  61. #define _END    "end"
  62.  
  63. #define _START    "__start"
  64.  
  65. /*
  66.  *   STORAGE CLASSES
  67.  */
  68.  
  69. #define  C_EFCN          -1    /* physical end of function */
  70. #define  C_NULL          0
  71. #define  C_AUTO          1     /* automatic variable */
  72. #define  C_EXT           2     /* external symbol */
  73. #define  C_STAT          3     /* static */
  74. #define  C_REG           4     /* register variable */
  75. #define  C_EXTDEF        5     /* external definition */
  76. #define  C_LABEL         6     /* label */
  77. #define  C_ULABEL        7     /* undefined label */
  78. #define  C_MOS           8     /* member of structure */
  79. #define  C_ARG           9     /* function argument */
  80. #define  C_STRTAG        10    /* structure tag */
  81. #define  C_MOU           11    /* member of union */
  82. #define  C_UNTAG         12    /* union tag */
  83. #define  C_TPDEF         13    /* type definition */
  84. #define  C_USTATIC     14    /* undefined static */
  85. #define  C_ENTAG         15    /* enumeration tag */
  86. #define  C_MOE           16    /* member of enumeration */
  87. #define  C_REGPARM     17    /* register parameter */
  88. #define  C_FIELD         18    /* bit field */
  89. #define  C_BLOCK         100   /* ".bb" or ".eb" */
  90. #define  C_FCN           101   /* ".bf" or ".ef" */
  91. #define  C_EOS           102   /* end of structure */
  92. #define  C_FILE          103   /* file name */
  93.  
  94.     /*
  95.      * The following storage class is a "dummy" used only by STS
  96.      * for line number entries reformatted as symbol table entries
  97.      */
  98.  
  99. #define  C_LINE         104
  100. #define  C_ALIAS     105   /* duplicate tag */
  101. #define  C_HIDDEN     106   /* special storage class for external */
  102.  
  103. /*        Number of characters in a symbol name */
  104. #define  SYMNMLEN    8
  105. /*        Number of characters in a file name */
  106. #define  FILNMLEN    14
  107. /*        Number of array dimensions in auxiliary entry */
  108. #define  DIMNUM        4
  109.  
  110.  
  111. struct syment
  112. {
  113.     union
  114.     {
  115.         char        _n_name[SYMNMLEN];    /* old COFF version */
  116.         struct
  117.         {
  118.             long    _n_zeroes;    /* new == 0 */
  119.             long    _n_offset;    /* offset into string table */
  120.         } _n_n;
  121.         char        *_n_nptr[2];    /* allows for overlaying */
  122.     } _n;
  123.     union {
  124.         CORE_ADDR _n_address; /* when an address */
  125.         unsigned long _n_val[2]; /* _n_val[0] is least significant */
  126.         }_n_value;    /* value of symbol */
  127.     short            n_scnum;    /* section number */
  128.     unsigned short        n_type;        /* type and derived type */
  129.     char            n_sclass;    /* storage class */
  130.     char            n_numaux;    /* number of aux. entries */
  131. };
  132.  
  133. #define n_name        _n._n_name
  134. #define n_nptr        _n._n_nptr[1]
  135. #define n_zeroes    _n._n_n._n_zeroes
  136. #define n_offset    _n._n_n._n_offset
  137. #define n_value _n_value._n_address
  138. /*
  139.    Relocatable symbols have a section number of the
  140.    section in which they are defined.  Otherwise, section
  141.    numbers have the following meanings:
  142. */
  143.         /* undefined symbol */
  144. #define  N_UNDEF    0
  145.         /* value of symbol is absolute */
  146. #define  N_ABS        -1
  147.         /* special debugging symbol -- value of symbol is meaningless */
  148. #define  N_DEBUG    -2
  149.  
  150. /*
  151.    The fundamental type of a symbol packed into the low 
  152.    4 bits of the word.
  153. */
  154.  
  155. #define  _EF    ".ef"
  156.  
  157. #define  T_NULL     0
  158. #define  T_ARG      1          /* function argument (only used by compiler) */
  159. #define  T_CHAR     2          /* character */
  160. #define  T_SHORT    3          /* short integer */
  161. #define  T_INT      4          /* integer */
  162. #define  T_LONG     5          /* long integer */
  163. #define  T_FLOAT    6          /* floating point */
  164. #define  T_DOUBLE   7          /* double word */
  165. #define  T_STRUCT   8          /* structure  */
  166. #define  T_UNION    9          /* union  */
  167. #define  T_ENUM     10         /* enumeration  */
  168. #define  T_MOE      11         /* member of enumeration */
  169. #define  T_UCHAR    12         /* unsigned character */
  170. #define  T_USHORT   13         /* unsigned short */
  171. #define  T_UINT     14         /* unsigned integer */
  172. #define  T_ULONG    15         /* unsigned long */
  173.  
  174. /*
  175.  * derived types are:
  176.  */
  177.  
  178. #define  DT_NON      0          /* no derived type */
  179. #define  DT_PTR      1          /* pointer */
  180. #define  DT_FCN      2          /* function */
  181. #define  DT_ARY      3          /* array */
  182.  
  183. /*
  184.  *   type packing constants
  185.  */
  186.  
  187. #define  N_BTMASK     017
  188. #define  N_TMASK      060
  189. #define  N_TMASK1     0300
  190. #define  N_TMASK2     0360
  191. #define  N_BTSHFT     4
  192. #define  N_TSHIFT     2
  193.  
  194. /*
  195.  *   MACROS
  196.  */
  197.  
  198.     /*   Basic Type of  x   */
  199.  
  200. #define  BTYPE(x)  ((x) & N_BTMASK)
  201.  
  202.     /*   Is  x  a  pointer ?   */
  203.  
  204. #define  ISPTR(x)  (((x) & N_TMASK) == (DT_PTR << N_BTSHFT))
  205.  
  206.     /*   Is  x  a  function ?  */
  207.  
  208. #define  ISFCN(x)  (((x) & N_TMASK) == (DT_FCN << N_BTSHFT))
  209.  
  210.     /*   Is  x  an  array ?   */
  211.  
  212. #define  ISARY(x)  (((x) & N_TMASK) == (DT_ARY << N_BTSHFT))
  213.  
  214.     /* Is x a structure, union, or enumeration TAG? */
  215.  
  216. #define ISTAG(x)  ((x)==C_STRTAG || (x)==C_UNTAG || (x)==C_ENTAG)
  217.  
  218. #define  INCREF(x) ((((x)&~N_BTMASK)<<N_TSHIFT)|(DT_PTR<<N_BTSHFT)|(x&N_BTMASK))
  219.  
  220. #define  DECREF(x) ((((x)>>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK))
  221.  
  222. /*
  223.  *    AUXILIARY ENTRY FORMAT
  224.  */
  225.  
  226. union auxent
  227. {
  228.     struct
  229.     {
  230.         long        x_tagndx;    /* str, un, or enum tag indx */
  231.         union
  232.         {
  233.             struct
  234.             {
  235.                 unsigned short    x_lnno;    /* declaration line number */
  236.                 unsigned short    x_size;    /* str, union, array size */
  237.             } x_lnsz;
  238.             long    x_fsize;    /* size of function */
  239.         } x_misc;
  240.         union
  241.         {
  242.             struct            /* if ISFCN, tag, or .bb */
  243.             {
  244.                 long    x_lnnoptr;    /* ptr to fcn line # */
  245.                 long    x_endndx;    /* entry ndx past block end */
  246.             }     x_fcn;
  247.             struct            /* if ISARY, up to 4 dimen. */
  248.             {
  249.                 unsigned short    x_dimen[DIMNUM];
  250.             }     x_ary;
  251.         }        x_fcnary;
  252.         unsigned short  x_tvndx;        /* tv index */
  253.     }     x_sym;
  254.     struct
  255.     {
  256.         char    x_fname[FILNMLEN]; /* filename here if x_foff==0 */
  257.         unsigned long x_foff; /* if !0 then x_fname in string table */
  258.     }     x_file;
  259.         struct
  260.         {
  261.                 long    x_scnlen;          /* section length */
  262.                 unsigned short  x_nreloc;  /* number of relocation entries */
  263.                 unsigned short  x_nlinno;  /* number of line numbers */
  264.                unsigned long x_soff; /* section name offset in string table (for named sections) */
  265.         }       x_scn;
  266.  
  267.     struct
  268.     {
  269.         long        x_tvfill;    /* tv fill value */
  270.         unsigned short    x_tvlen;    /* length of .tv */
  271.         unsigned short    x_tvran[2];    /* tv range */
  272.     }    x_tv;    /* info about .tv section (in auxent of symbol .tv)) */
  273. struct syment filler; /* to fill out to size of syment */
  274. };
  275.  
  276. #define    SYMENT    struct syment
  277. #define    SYMESZ    (sizeof(SYMENT))
  278.  
  279. #define    AUXENT    union auxent
  280. #define    AUXESZ    (sizeof(AUXENT)) 
  281.  
  282. #endif
  283. /* #include <storclass.h>  used to be this instead of syms.h.  */
  284.  
  285. /* Line number of beginning of current function, minus one.  */
  286.  
  287. int sdb_begin_function_line = 0;
  288.  
  289. /* Counter to generate unique "names" for nameless struct members.  */
  290.  
  291. static int unnamed_struct_number = 0;
  292.  
  293. extern FILE *asm_out_file;
  294.  
  295. extern tree current_function_decl;
  296.  
  297. #if defined( _MSDOS )
  298. void warning ( char * s, ... );
  299. #endif
  300.  
  301. void sdbout_init ();
  302. void sdbout_symbol ();
  303. void sdbout_tags();
  304. void sdbout_types();
  305.  
  306. static void sdbout_syms ();
  307. static void sdbout_one_type ();
  308. static int plain_type_1 ();
  309.  
  310. /* Random macros describing parts of SDB data.  */
  311.  
  312. /* Put something here if lines get too long */
  313. #define CONTIN
  314.  
  315. #ifndef PUT_SDB_SCL
  316. #if ! defined( DSP56000 ) && ! defined( DSP96000 )
  317. #define PUT_SDB_SCL(a) fprintf(asm_out_file, "\t.scl\t%d;", (a))
  318. #else
  319. #define PUT_SDB_SCL(a) fprintf(asm_out_file, "\t.scl\t%d\n", (a))
  320. #endif /* dsp */
  321. #endif
  322.  
  323. #ifndef PUT_SDB_INT_VAL
  324. #if ! defined( DSP56000 ) && ! defined( DSP96000 )
  325. #define PUT_SDB_INT_VAL(a) fprintf (asm_out_file, "\t.val\t%d;", (a))
  326. #else
  327. #define PUT_SDB_INT_VAL(a) fprintf (asm_out_file, "\t.val\t%d\n", (a))
  328. #endif /* dsp */
  329. #endif
  330.  
  331. #ifndef PUT_SDB_VAL
  332. #if ! defined( DSP56000 ) && ! defined( DSP96000 )
  333. #define PUT_SDB_VAL(a)                \
  334. ( fputs ("\t.val\t", asm_out_file),        \
  335.   output_addr_const (asm_out_file, (a)),    \
  336.   fputc (';', asm_out_file))
  337. #else
  338. #define PUT_SDB_VAL(a)                \
  339. ( fputs ("\t.val\t", asm_out_file),        \
  340.   output_addr_const (asm_out_file, (a)),    \
  341.   fputc ('\n', asm_out_file))
  342. #endif /* dsp */
  343. #endif
  344.  
  345. #ifndef PUT_SDB_DEF
  346. #if ! defined( DSP56000 ) && ! defined( DSP96000 )
  347. #define PUT_SDB_DEF(a)                \
  348. do { fprintf (asm_out_file, "\t.def\t");    \
  349.      ASM_OUTPUT_LABELREF (asm_out_file, a);     \
  350.      fprintf (asm_out_file, ";"); } while (0)
  351. #else
  352. #define PUT_SDB_DEF(a)                \
  353. do { fprintf (asm_out_file, "\t.def\t");    \
  354.      ASM_OUTPUT_LABELREF (asm_out_file, a);     \
  355.      fprintf (asm_out_file, "\n"); } while (0)
  356. #endif
  357. #endif
  358.  
  359. #ifndef PUT_SDB_PLAIN_DEF
  360. #if ! defined( DSP56000 ) && ! defined( DSP96000 )
  361. #define PUT_SDB_PLAIN_DEF(a) fprintf(asm_out_file,"\t.def\t.%s;",a)
  362. #else
  363. #define PUT_SDB_PLAIN_DEF(a) fprintf(asm_out_file,"\t.def\t.%s\n",a)
  364. #endif /* dsp */
  365. #endif
  366.  
  367. #ifndef PUT_SDB_ENDEF
  368. #define PUT_SDB_ENDEF fputs("\t.endef\n", asm_out_file)
  369. #endif
  370.  
  371. #ifndef PUT_SDB_TYPE
  372. #if ! defined( DSP56000 ) && ! defined( DSP96000 )
  373. #define PUT_SDB_TYPE(a) fprintf(asm_out_file, "\t.type\t0%o;", a)
  374. #else
  375. #define PUT_SDB_TYPE(a) fprintf(asm_out_file, "\t.type\t$%x\n", a)
  376. #endif /* dsp */
  377. #endif
  378.  
  379. #ifndef PUT_SDB_SIZE
  380. #if ! defined( DSP56000 ) && ! defined( DSP96000 )
  381. #define PUT_SDB_SIZE(a) fprintf(asm_out_file, "\t.size\t%d;", a)
  382. #else
  383. #define PUT_SDB_SIZE(a) fprintf(asm_out_file, "\t.size\t%d\n", a)
  384. #endif /* dsp */
  385. #endif
  386.  
  387. #ifndef PUT_SDB_DIM
  388. #if ! defined( DSP56000 ) && ! defined( DSP96000 )
  389. #define PUT_SDB_DIM(a) fprintf(asm_out_file, "\t.dim\t%d;", a)
  390. #else
  391. #define PUT_SDB_DIM(a) fprintf(asm_out_file, "\t.dim\t%d\n", a)
  392. #endif /* dsp */
  393. #endif
  394.  
  395. #ifndef PUT_SDB_TAG
  396. #if ! defined( DSP56000 ) && ! defined( DSP96000 )
  397. #define PUT_SDB_TAG(a)                \
  398. do { fprintf (asm_out_file, "\t.tag\t");    \
  399.      ASM_OUTPUT_LABELREF (asm_out_file, a);    \
  400.      fprintf (asm_out_file, ";"); } while (0)
  401. #else
  402. #define PUT_SDB_TAG(a)                \
  403. do { fprintf (asm_out_file, "\t.tag\t");    \
  404.      ASM_OUTPUT_LABELREF (asm_out_file, a);    \
  405.      fprintf (asm_out_file, "\n"); } while (0)
  406. #endif /* dsp */
  407. #endif
  408.  
  409. #ifndef PUT_SDB_BLOCK_START
  410. #if ! defined( DSP56000 ) && ! defined( DSP96000 )
  411. #define PUT_SDB_BLOCK_START(LINE)        \
  412.   fprintf (asm_out_file,            \
  413.        "\t.def\t.bb;\t.val\t.;\t.scl\t100;\t.line\t%d;\t.endef\n",    \
  414.        (LINE))
  415. #else
  416. #define PUT_SDB_BLOCK_START(LINE)        \
  417.     fprintf( asm_out_file, "\t.bb\t%d\n", (LINE) )
  418. #endif /* dsp5/96k */
  419. #endif
  420.  
  421. #ifndef PUT_SDB_BLOCK_END
  422. #if ! defined( DSP56000 ) && ! defined( DSP96000 )
  423. #define PUT_SDB_BLOCK_END(LINE)            \
  424.   fprintf (asm_out_file,            \
  425.        "\t.def\t.eb;.val\t.;\t.scl\t100;\t.line\t%d;\t.endef\n",    \
  426.        (LINE))
  427. #else
  428. #define PUT_SDB_BLOCK_END(LINE)            \
  429.     fprintf( asm_out_file, "\t.eb\t%d\n", (LINE) )
  430. #endif /* dsp */
  431. #endif
  432.  
  433. #ifndef PUT_SDB_FUNCTION_START
  434. #if ! defined( DSP56000 ) && ! defined( DSP96000 )
  435. #define PUT_SDB_FUNCTION_START(LINE)        \
  436.   fprintf (asm_out_file,            \
  437.        "\t.def\t.bf;\t.val\t.;\t.scl\t101;\t.line\t%d;\t.endef\n",    \
  438.        (LINE))
  439. #else
  440. #define PUT_SDB_FUNCTION_START(LINE)        \
  441.     fprintf( asm_out_file, "\t.bf\t%d,%d\n", (LINE), logue_index )
  442. #endif /* dsp */
  443. #endif
  444.  
  445. #ifndef PUT_SDB_FUNCTION_END
  446. #if ! defined( DSP56000 ) && ! defined( DSP96000 )
  447. #define PUT_SDB_FUNCTION_END(LINE)        \
  448.   fprintf (asm_out_file,            \
  449.        "\t.def\t.ef;\t.val\t.;\t.scl\t101;\t.line\t%d;\t.endef\n",    \
  450.        (LINE))
  451. #else
  452. #define PUT_SDB_FUNCTION_END(LINE)        \
  453.     fprintf( asm_out_file, "\t.ef\t%d\n", (LINE) )
  454. #endif /* dsp */
  455. #endif
  456.  
  457. #ifndef PUT_SDB_EPILOGUE_END
  458. #if ! defined( DSP56000 ) && ! defined( DSP96000 )
  459. #define PUT_SDB_EPILOGUE_END(NAME)        \
  460.   fprintf (asm_out_file,            \
  461.        "\t.def\t%s;\t.val\t.;\t.scl\t-1;\t.endef\n",    \
  462.        (NAME))
  463. #else
  464. #define PUT_SDB_EPILOGUE_END(NAME)        \
  465.   fprintf (asm_out_file,            \
  466.        "\t.def\tF%s\n\t.val\t*\n\t.scl\t-1\n\t.endef\n",    \
  467.        (NAME))
  468. #endif /* dsp */
  469. #endif
  470.  
  471. #ifndef SDB_GENERATE_FAKE
  472. #define SDB_GENERATE_FAKE(BUFFER, NUMBER) \
  473.   sprintf ((BUFFER), ".%dfake", (NUMBER));
  474. #endif
  475.  
  476. /* Return the sdb tag identifier string for TYPE
  477.    if TYPE has already been defined; otherwise return a null pointer.   */
  478.   
  479. #define KNOWN_TYPE_TAG(type) (char *)(TYPE_SYMTAB_ADDRESS (type))
  480.  
  481. /* Set the sdb tag identifier string for TYPE to NAME.  */
  482.  
  483. #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
  484.   (TYPE_SYMTAB_ADDRESS (TYPE) = (int)(NAME))
  485.  
  486. /* Return the name (a string) of the struct, union or enum tag
  487.    described by the TREE_LIST node LINK.  This is 0 for an anonymous one.  */
  488.  
  489. #define TAG_NAME(link) \
  490.   (((link) && TREE_PURPOSE ((link)) \
  491.     && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \
  492.    ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0)
  493.  
  494. /* Ensure we don't output a negative line number.  */
  495. #define MAKE_LINE_SAFE(line)  \
  496.   if (line <= sdb_begin_function_line) line = sdb_begin_function_line + 1
  497.  
  498. /* Tell the assembler the source file name.
  499.    On systems that use SDB, this is done whether or not -g,
  500.    so it is called by ASM_FILE_START.
  501.  
  502.    ASM_FILE is the assembler code output file,
  503.    INPUT_NAME is the name of the main input file.  */
  504.  
  505. void
  506. sdbout_filename (asm_file, input_name)
  507.      FILE *asm_file;
  508.      char *input_name;
  509. {
  510. #if defined( DSP56000 ) || defined( DSP96000 )
  511. #ifdef ASM_OUTPUT_SOURCE_FILENAME
  512.   ASM_OUTPUT_SOURCE_FILENAME (asm_file, input_name);
  513. #else
  514.   fprintf (asm_file, "\t.file\t\"%s\",%d\n", input_name,
  515.        (( 'l' == memory_model ) ? 3 : (( 'x' == memory_model ) ? 2 : 1 )));
  516. #endif
  517. #else
  518.   int len = strlen (input_name);
  519.   char *na = input_name + len;
  520.  
  521.   /* we want the path here */
  522.   /* NA gets INPUT_NAME sans directory names.  */
  523.   while (na > input_name)
  524.     {
  525.       if (na[-1] == '/')
  526.     break;
  527.       na--;
  528.     }
  529.  
  530. #ifdef ASM_OUTPUT_SOURCE_FILENAME
  531.   ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
  532. #else
  533.   fprintf (asm_file, "\t.file\t\"%s\"\n", na);
  534. #endif
  535. #endif
  536. }
  537.  
  538. /* Set up for SDB output at the start of compilation.  */
  539.  
  540. void
  541. sdbout_init ()
  542. {
  543.   /* Output all the initial permanent types.  */
  544.   sdbout_types (nreverse (get_permanent_types ()));
  545. }
  546.  
  547. #if 0
  548.  
  549. /* return the tag identifier for type
  550.  */
  551.  
  552. {
  553. char *
  554. tag_of_ru_type (type,link)
  555.      tree type,link;
  556. {
  557.   if (TYPE_SYMTAB_ADDRESS (type))
  558.     return (char *)TYPE_SYMTAB_ADDRESS (type);
  559.   if (link &&
  560.       TREE_PURPOSE (link)
  561.       && IDENTIFIER_POINTER (TREE_PURPOSE (link)))
  562.     TYPE_SYMTAB_ADDRESS (type) =
  563.       (int)IDENTIFIER_POINTER (TREE_PURPOSE (link));
  564.   else
  565.     return (char *) TYPE_SYMTAB_ADDRESS (type);
  566. }
  567. #endif
  568.  
  569. /* Return a unique string to name an anonymous type.  */
  570.  
  571. static char *
  572. gen_fake_label ()
  573. {
  574.   char label[10];
  575.   char *labelstr;
  576.   SDB_GENERATE_FAKE (label, unnamed_struct_number);
  577.   unnamed_struct_number++;
  578.   labelstr = (char *) permalloc (strlen (label) + 1);
  579.   strcpy (labelstr, label);
  580.   return labelstr;
  581. }
  582.  
  583. /* Return the number which describes TYPE for SDB.
  584.    For pointers, etc., this function is recursive.
  585.    Each record, union or enumeral type must already have had a
  586.    tag number output.  */
  587.  
  588. /* The number is given by d6d5d4d3d2d1bbbb 
  589.    where bbbb is 4 bit basic type, and di indicate  one of notype,ptr,fn,array.
  590.    Thus, char *foo () has bbbb=T_CHAR
  591.               d1=D_FCN
  592.               d2=D_PTR
  593.  N_BTMASK=     017       1111     basic type field.
  594.  N_TSHIFT=       2                derived type shift
  595.  N_BTSHFT=       4                Basic type shift */
  596.  
  597. /* Produce the number that describes a pointer, function or array type.
  598.    PREV is the number describing the target, value or element type.
  599.    DT_type describes how to transform that type.  */
  600. #if defined( DSP56000 ) || defined( DSP96000 )
  601. static int push_derived_level( );
  602. #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
  603.   push_derived_level(DT_type,PREV)
  604. #else
  605. #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
  606.   ((((PREV)&~N_BTMASK)<<N_TSHIFT)|(DT_type<<N_BTSHFT)|(PREV&N_BTMASK))
  607. #endif
  608.  
  609. static int
  610. plain_type (type)
  611.      tree type;
  612. {
  613.   int val = plain_type_1 (type);
  614.   if (TREE_CODE (type) == ARRAY_TYPE)
  615.     {
  616.       int size = int_size_in_bytes (type);
  617.       /* Don't kill sdb if type is not laid out or has variable size.  */
  618.       if (size < 0)
  619.     size = 0;
  620.       PUT_SDB_SIZE (size);
  621.     }
  622.   return val;
  623. }
  624.  
  625. static void
  626. sdbout_record_type_name (type)
  627.      tree type;
  628. {
  629.   char *name = 0;
  630.  
  631.   if (KNOWN_TYPE_TAG (type))
  632.     return;
  633.  
  634.   if (TYPE_NAME (type) != 0) 
  635.     {
  636.       tree t = 0;
  637.       /* Find the IDENTIFIER_NODE for the type name.  */
  638.       if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
  639.     {
  640.       t = TYPE_NAME (type);
  641.     }
  642.       else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
  643.     {
  644.       t = DECL_NAME (TYPE_NAME (type));
  645.     }
  646.  
  647.       /* Now get the name as a string, or invent one.  */
  648.       if (t != 0)
  649.     name = IDENTIFIER_POINTER (t);
  650.     }
  651.  
  652.   if (name == 0)
  653.     name = gen_fake_label ();
  654.  
  655.   SET_KNOWN_TYPE_TAG (type, name);
  656. }
  657.  
  658. static int
  659. plain_type_1 (type)
  660.     tree type;
  661. {
  662.     if (type == 0)
  663.     {
  664.     type = void_type_node;
  665.     }
  666.     
  667.     if (type == error_mark_node)
  668.     {
  669.     type = integer_type_node;
  670.     }
  671.     
  672.     type = TYPE_MAIN_VARIANT (type);
  673.  
  674.     switch (TREE_CODE (type))
  675.     {
  676.     case VOID_TYPE:
  677.     return T_INT;
  678.     
  679.     case INTEGER_TYPE:
  680.     switch (int_size_in_bytes (type))
  681.     {
  682. #if ! defined( DSP56000 ) && ! defined ( DSP96000 )
  683.     case 4:
  684.         return (TREE_UNSIGNED (type) ? T_UINT : T_INT);
  685.     case 1:
  686.         return (TREE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
  687.     case 2:
  688.         return (TREE_UNSIGNED (type) ? T_USHORT : T_SHORT);
  689. #else
  690.         /* char, short, int are all same size */
  691.         /* don't forget that long is also the same size in l-memory */
  692.     case 1:
  693.         if ( char_type_node == type )
  694.         {
  695.         return T_CHAR;
  696.         }
  697.         else if ( unsigned_char_type_node == type )
  698.         {
  699.         return T_UCHAR;
  700.         }
  701.         else if ( long_integer_type_node == type )
  702.         {
  703.         return T_LONG;
  704.         }
  705.         else if ( long_unsigned_type_node == type )
  706.         {
  707.         return T_ULONG;
  708.         }
  709.         else
  710.         {
  711.         return (TREE_UNSIGNED (type) ? T_UINT : T_INT);
  712.         }
  713.  
  714.     case 2:
  715.         return(TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
  716. #endif
  717.     default:
  718.         return 0;
  719.     }
  720.  
  721.     case REAL_TYPE:
  722.     switch (int_size_in_bytes (type))
  723.     {
  724. #if defined( DSP56000 ) || defined( DSP96000 )
  725.     default:
  726.         return (( double_type_node == type ) ? T_DOUBLE : T_FLOAT );
  727. #else
  728.     case 4:
  729.         return T_FLOAT;
  730.     default:
  731.         return T_DOUBLE;
  732. #endif
  733.     }
  734.  
  735.     case ARRAY_TYPE:
  736.     {
  737.     int m = plain_type (TREE_TYPE (type));
  738.     PUT_SDB_DIM (TYPE_DOMAIN (type)
  739.              ? TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) + 1
  740.              : 0);
  741.     return PUSH_DERIVED_LEVEL (DT_ARY, m);
  742.     }
  743.  
  744.     case RECORD_TYPE:
  745.     case UNION_TYPE:
  746.     case ENUMERAL_TYPE:
  747.     {
  748.     char *tag;
  749.     int size;
  750.     sdbout_record_type_name (type);
  751.  
  752.     if (TREE_ASM_WRITTEN (type))
  753.     {
  754.         /* Output the referenced structure tag name
  755.            only if the .def has already been output.
  756.            At least on 386, the Unix assembler
  757.            cannot handle forward references to tags.  */
  758.         tag = KNOWN_TYPE_TAG (type);
  759.         PUT_SDB_TAG (tag);
  760.     }
  761.     size = int_size_in_bytes (type);
  762.  
  763.     if (size < 0)
  764.     {
  765.         size = 0;
  766.     }
  767.     
  768.     PUT_SDB_SIZE (size);
  769.  
  770.     return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
  771.         : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
  772.         : T_ENUM);
  773.     }
  774.  
  775.     case POINTER_TYPE:
  776.     case REFERENCE_TYPE:
  777.     {
  778.     int m = plain_type (TREE_TYPE (type));
  779.     return PUSH_DERIVED_LEVEL (DT_PTR, m);
  780.     }
  781.  
  782.     case FUNCTION_TYPE:
  783.     case METHOD_TYPE:
  784.     {
  785.     int m = plain_type (TREE_TYPE (type));
  786.     return PUSH_DERIVED_LEVEL (DT_FCN, m);
  787.     }
  788.  
  789.     default:
  790.     return 0;
  791.     }
  792. }
  793.  
  794. /* Output the symbols defined in block number DO_BLOCK.
  795.    Set NEXT_BLOCK_NUMBER to 0 before calling.
  796.  
  797.    This function works by walking the tree structure,
  798.    counting blocks, until it finds the desired block.  */
  799.  
  800. static int do_block = 0;
  801.  
  802. static int next_block_number;
  803.  
  804. static void
  805. sdbout_block (stmt)
  806.      register tree stmt;
  807. {
  808.   while (stmt)
  809.     {
  810.       switch (TREE_CODE (stmt))
  811.     {
  812.     case COMPOUND_STMT:
  813.     case LOOP_STMT:
  814.       sdbout_block (STMT_BODY (stmt));
  815.       break;
  816.  
  817.     case IF_STMT:
  818.       sdbout_block (STMT_THEN (stmt));
  819.       sdbout_block (STMT_ELSE (stmt));
  820.       break;
  821.  
  822.     case LET_STMT:
  823.       /* Ignore LET_STMTs for blocks never really used to make RTL.  */
  824.       if (! TREE_USED (stmt))
  825.         break;
  826.       /* When we reach the specified block, output its symbols.  */
  827.       if (next_block_number == do_block)
  828.         {
  829.           sdbout_tags (STMT_TYPE_TAGS (stmt));
  830.           sdbout_syms (STMT_VARS (stmt));
  831.         }
  832.  
  833.       /* If we are past the specified block, stop the scan.  */
  834.       if (next_block_number > do_block)
  835.         return;
  836.  
  837.       next_block_number++;
  838.  
  839.       /* Scan the blocks within this block.  */
  840.       sdbout_block (STMT_SUBBLOCKS (stmt));
  841.     }
  842.       stmt = TREE_CHAIN (stmt);
  843.     }
  844. }
  845.  
  846. /* Call sdbout_symbol on each decl in the chain SYMS.  */
  847.  
  848. static void
  849. sdbout_syms (syms)
  850.      tree syms;
  851. {
  852.   while (syms)
  853.     {
  854.       sdbout_symbol (syms, 1);
  855.       syms = TREE_CHAIN (syms);
  856.     }
  857. }
  858.  
  859. /* Output SDB information for a symbol described by DECL.
  860.    LOCAL is nonzero if the symbol is not file-scope.  */
  861.  
  862. void
  863. sdbout_symbol (decl, local)
  864.      tree decl;
  865.      int local;
  866. {
  867.   int letter = 0;
  868.   tree type = TREE_TYPE (decl);
  869.  
  870.   /* If global, first output all types and all
  871.      struct, enum and union tags that have been created
  872.      and not yet output.  */
  873.  
  874.   if (local == 0)
  875.     {
  876. #if defined( __WATCOMC__ )
  877.     extern tree gettags();
  878. #endif
  879.       sdbout_tags (gettags ());
  880.       sdbout_types (nreverse (get_permanent_types ()));
  881.     }
  882.  
  883.   switch (TREE_CODE (decl))
  884.     {
  885.     case CONST_DECL:
  886.       /* Enum values are defined by defining the enum type.  */
  887.       return;
  888.  
  889.     case FUNCTION_DECL:
  890.       if (TREE_EXTERNAL (decl))
  891.     return;
  892.       if (GET_CODE (DECL_RTL (decl)) != MEM
  893.       || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
  894.     return;
  895.  
  896.       PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
  897.       PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
  898.       PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
  899.       break;
  900.  
  901.     case TYPE_DECL:
  902.       /* Output typedef name.  */
  903.       PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
  904.       PUT_SDB_SCL (C_TPDEF);
  905.       break;
  906.       
  907.     case PARM_DECL:
  908.       /* Parm decls go in their own separate chains
  909.      and are output by sdbout_reg_parms and sdbout_parms.  */
  910.       abort ();
  911.  
  912.     case VAR_DECL:
  913.       /* Don't mention a variable that is external.
  914.      Let the file that defines it describe it.  */
  915.       if (TREE_EXTERNAL (decl))
  916.     return;
  917.  
  918.       /* Don't mention a variable at all
  919.      if it was completely optimized into nothingness.  */
  920.       if (GET_CODE (DECL_RTL (decl)) == REG
  921.       && (REGNO (DECL_RTL (decl)) < 0
  922.           || REGNO (DECL_RTL (decl)) >= FIRST_PSEUDO_REGISTER))
  923.     return;
  924.  
  925.       /* Ok, start a symtab entry and output the variable name.  */
  926. #if defined( DSP56000 ) || defined( DSP56100 ) || defined( DSP96000 )
  927.       put_sdb_def( decl );
  928. #else
  929.       PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
  930. #endif
  931.  
  932.       if (GET_CODE (DECL_RTL (decl)) == MEM
  933.       && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
  934.     {
  935.       if (TREE_PUBLIC (decl))
  936.         {
  937.           PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
  938.               PUT_SDB_SCL (C_EXT);
  939.         }
  940.       else
  941.         {
  942.           PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
  943.               PUT_SDB_SCL (C_STAT);
  944.         }
  945.     }
  946.       else if (GET_CODE (DECL_RTL (decl)) == REG)
  947.     {
  948.       PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (decl))));
  949.       PUT_SDB_SCL (C_REG);
  950.     }
  951.       else if (GET_CODE (DECL_RTL (decl)) == MEM
  952.            && (GET_CODE (XEXP (DECL_RTL (decl), 0)) == MEM
  953.            || (GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG
  954.                && REGNO (XEXP (DECL_RTL (decl), 0)) != FRAME_POINTER_REGNUM)))
  955.     /* If the value is indirect by memory or by a register
  956.        that isn't the frame pointer
  957.        then it means the object is variable-sized and address through
  958.        that register or stack slot.  DBX has no way to represent this
  959.        so all we can do is output the variable as a pointer.  */
  960.     {
  961.       if (GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG)
  962.         {
  963.           PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (decl))));
  964.           PUT_SDB_SCL (C_REG);
  965.         }
  966.       else
  967.         {
  968.           /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
  969.          (CONST_INT...)))).
  970.          We want the value of that CONST_INT.  */
  971.           /* Encore compiler hates a newline in a macro arg, it seems.  */
  972.           PUT_SDB_INT_VAL (INTVAL (XEXP (XEXP (XEXP (DECL_RTL (decl), 0), 0), 1)));
  973.           PUT_SDB_SCL (C_AUTO);
  974.         }
  975.  
  976.       type = build_pointer_type (TREE_TYPE (decl));
  977.     }
  978.       else if (GET_CODE (DECL_RTL (decl)) == MEM
  979.            && GET_CODE (XEXP (DECL_RTL (decl), 0)) == PLUS
  980.            && GET_CODE (XEXP (XEXP (DECL_RTL (decl), 0), 0)) == REG
  981.            && GET_CODE (XEXP (XEXP (DECL_RTL (decl), 0), 1)) == CONST_INT)
  982.     {
  983.       /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))).
  984.          We want the value of that CONST_INT.  */
  985.       PUT_SDB_INT_VAL (INTVAL (XEXP (XEXP (DECL_RTL (decl), 0), 1)));
  986.       PUT_SDB_SCL (C_AUTO);
  987.     }
  988.       else
  989.     {
  990.       /* It is something we don't know how to represent for SDB.  */
  991.     }
  992.       break;
  993.     }
  994.   PUT_SDB_TYPE (plain_type (type));
  995.   PUT_SDB_ENDEF;
  996. }
  997.  
  998. /* Given a list of TREE_LIST nodes that point at types,
  999.    output those types for SDB.
  1000.    We must check to include those that have been mentioned already with
  1001.    only a cross-reference.  */
  1002.  
  1003. void
  1004. sdbout_tags (tags)
  1005.      tree tags;
  1006. {
  1007.   register tree link;
  1008.  
  1009.   for (link = tags; link; link = TREE_CHAIN (link))
  1010.     {
  1011.       register tree type = TREE_VALUE (link);
  1012.  
  1013.       if (TREE_PURPOSE (link) != 0
  1014.       && TYPE_SIZE (type) != 0)
  1015.     sdbout_one_type (type);
  1016.     }
  1017. }
  1018.  
  1019. /* Given a chain of ..._TYPE nodes, all of which have names,
  1020.    output definitions of those names, as typedefs.  */
  1021.  
  1022. void
  1023. sdbout_types (types)
  1024.      register tree types;
  1025. {
  1026.   register tree link;
  1027.  
  1028.   for (link = types; link; link = TREE_CHAIN (link))
  1029.     sdbout_one_type (link);
  1030. }
  1031.  
  1032. static void
  1033. sdbout_type (type)
  1034.      tree type;
  1035. {
  1036.   register tree tem;
  1037.   if (type == error_mark_node)
  1038.     type = integer_type_node;
  1039.   PUT_SDB_TYPE (plain_type (type));
  1040. }
  1041.  
  1042. /* Output types of the fields of type TYPE, if they are structs.
  1043.    Don't chase through pointer types, since that could be circular.
  1044.    They must come before TYPE, since forward refs are not allowed.
  1045.  
  1046.    This is not actually used, since the COFF assembler rejects the
  1047.    results.  No one knows why it rejects them.  */
  1048.  
  1049. static void
  1050. sdbout_field_types (type)
  1051.      tree type;
  1052. {
  1053.   tree tail;
  1054.   for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
  1055.     sdbout_one_type (TREE_TYPE (tail));
  1056. }
  1057.  
  1058. /* Use this to put out the top level defined record and union types
  1059.    for later reference.  If this is a struct with a name, then put that
  1060.    name out.  Other unnamed structs will have .xxfake labels generated so
  1061.    that they may be referred to later.
  1062.    The label will be stored in the KNOWN_TYPE_TAG slot of a type.
  1063.    It may NOT be called recursively.  */
  1064.  
  1065. static void
  1066. sdbout_one_type (type)
  1067.      tree type;
  1068. {
  1069.   text_section ();
  1070.  
  1071.   switch (TREE_CODE (type))
  1072.     {
  1073.     case RECORD_TYPE:
  1074.     case UNION_TYPE:
  1075.     case ENUMERAL_TYPE:
  1076.       type = TYPE_MAIN_VARIANT (type);
  1077.       /* Don't output a type twice.  */
  1078.       if (TREE_ASM_WRITTEN (type))
  1079.     return;
  1080.  
  1081.       TREE_ASM_WRITTEN (type) = 1;
  1082. #if 0  /* This change, which ought to make better output,
  1083.       makes the COFF assembler unhappy.  */
  1084.       /* Before really doing anything, output types we want to refer to.  */
  1085.       if (TREE_CODE (type) != ENUMERAL_TYPE)
  1086.     sdbout_field_types (type);
  1087. #endif
  1088.  
  1089.       sdbout_record_type_name (type);
  1090.  
  1091.       /* Output a structure type.  */
  1092.       {
  1093.     int size = int_size_in_bytes (type);
  1094.     int member_scl;
  1095.     tree tem;
  1096.  
  1097.     PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
  1098.  
  1099.     switch (TREE_CODE (type))
  1100.       {
  1101.       case UNION_TYPE:
  1102.         PUT_SDB_SCL (C_UNTAG);
  1103.         PUT_SDB_TYPE (T_UNION);
  1104.         member_scl = C_MOU;
  1105.         break;
  1106.  
  1107.       case RECORD_TYPE:
  1108.         PUT_SDB_SCL (C_STRTAG);
  1109.         PUT_SDB_TYPE (T_STRUCT);
  1110.         member_scl = C_MOS;
  1111.         break;
  1112.  
  1113.       case ENUMERAL_TYPE:
  1114.         PUT_SDB_SCL (C_ENTAG);
  1115.         PUT_SDB_TYPE (T_ENUM);
  1116.         member_scl = C_MOE;
  1117.         break;
  1118.       }
  1119.  
  1120.     PUT_SDB_SIZE (size);
  1121.     PUT_SDB_ENDEF;
  1122.  
  1123.     /* output the individual fields */
  1124.  
  1125.     if (TREE_CODE (type) == ENUMERAL_TYPE)
  1126.       for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
  1127.         {
  1128.           PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
  1129.           PUT_SDB_INT_VAL (TREE_INT_CST_LOW (TREE_VALUE (tem)));
  1130.           PUT_SDB_SCL (C_MOE);
  1131.           PUT_SDB_TYPE (T_MOE);
  1132.           PUT_SDB_ENDEF;
  1133.         }
  1134.       
  1135.     else            /* record or union type */
  1136.       for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
  1137.         /* Output the name, type, position (in bits), size (in bits)
  1138.            of each field.  */
  1139.         /* Omit here the nameless fields that are used to skip bits.  */
  1140.         if (DECL_NAME (tem) != 0)
  1141.           {
  1142.         CONTIN;
  1143.         PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (tem)));
  1144.         if (TREE_PACKED (tem))
  1145.           {
  1146.             PUT_SDB_INT_VAL (DECL_OFFSET (tem));
  1147.             PUT_SDB_SCL (C_FIELD);
  1148.             sdbout_type (TREE_TYPE (tem));
  1149.             PUT_SDB_SIZE (TREE_INT_CST_LOW (DECL_SIZE (tem))
  1150.                   * DECL_SIZE_UNIT (tem));
  1151.           }
  1152.         else
  1153.           {
  1154.             PUT_SDB_INT_VAL (DECL_OFFSET (tem) / BITS_PER_UNIT);
  1155.             PUT_SDB_SCL (member_scl);
  1156.             sdbout_type (TREE_TYPE (tem));
  1157.           }
  1158.         PUT_SDB_ENDEF;
  1159.           }
  1160.     /* output end of a structure,union, or enumeral definition */
  1161.    
  1162.     PUT_SDB_PLAIN_DEF ("eos");
  1163.     PUT_SDB_INT_VAL (size);
  1164.     PUT_SDB_SCL (C_EOS);
  1165.     PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
  1166.     PUT_SDB_SIZE (size);
  1167.     PUT_SDB_ENDEF;
  1168.     break;
  1169.       }
  1170.     }
  1171. }
  1172.  
  1173. /* Output definitions of all parameters, referring when possible to the
  1174.    place where the parameters were passed rather than the copies used
  1175.    within the function.     This is done as part of starting the function.
  1176.    PARMS is a chain of PARM_DECL nodes.  */
  1177.  
  1178. static void
  1179. sdbout_parms (parms1)
  1180.      tree parms1;
  1181. {
  1182.   tree type;
  1183.   tree parms;
  1184.  
  1185.   for (parms = parms1; parms; parms = TREE_CHAIN (parms))
  1186.     {
  1187.       int current_sym_value = DECL_OFFSET (parms) / BITS_PER_UNIT;
  1188.  
  1189.       if (DECL_NAME (parms))
  1190.     PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (parms)));
  1191.       else
  1192.     PUT_SDB_DEF (gen_fake_label ());
  1193.  
  1194.       if (GET_CODE (DECL_RTL (parms)) == REG
  1195.       && REGNO (DECL_RTL (parms)) >= 0
  1196.       && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
  1197.     type = DECL_ARG_TYPE (parms);
  1198.       else
  1199.     {
  1200.       /* This is the case where the parm is passed as an int or double
  1201.          and it is converted to a char, short or float and stored back
  1202.          in the parmlist.  In this case, describe the parm
  1203.          with the variable's declared type, and adjust the address
  1204.          if the least significant bytes (which we are using) are not
  1205.          the first ones.  */
  1206. #ifdef BYTES_BIG_ENDIAN
  1207.       if (TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
  1208.         current_sym_value +=
  1209.           (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
  1210.            - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
  1211. #endif
  1212.       if (GET_CODE (DECL_RTL (parms)) == MEM
  1213.           && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
  1214.           && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
  1215.           && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
  1216.           == current_sym_value))
  1217.         type = TREE_TYPE (parms);
  1218.       else
  1219.         {
  1220.           current_sym_value = DECL_OFFSET (parms) / BITS_PER_UNIT;
  1221.           type = DECL_ARG_TYPE (parms);
  1222.         }
  1223.     }
  1224.      
  1225. #if defined( DSP56000 ) || defined( DSP96000 )
  1226.       if (GET_CODE (DECL_RTL (parms)) == REG
  1227.       && REGNO (DECL_RTL (parms)) >= 0
  1228.       && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
  1229.       {
  1230.       PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
  1231.         PUT_SDB_SCL (C_REGPARM);
  1232.       PUT_SDB_TYPE (plain_type (type));
  1233.       PUT_SDB_ENDEF;
  1234.       }
  1235.       else
  1236.       {
  1237.       PUT_SDB_INT_VAL (current_sym_value);
  1238.       PUT_SDB_SCL (C_ARG);
  1239.       PUT_SDB_TYPE (plain_type (type));
  1240.       PUT_SDB_ENDEF;
  1241.       }
  1242. #else
  1243.       PUT_SDB_INT_VAL (current_sym_value);
  1244.       PUT_SDB_SCL (C_ARG);
  1245.       PUT_SDB_TYPE (plain_type (type));
  1246.       PUT_SDB_ENDEF;
  1247. #endif
  1248.     }
  1249. }
  1250.  
  1251. /* Output definitions, referring to registers,
  1252.    of all the parms in PARMS which are stored in registers during the function.
  1253.    PARMS is a chain of PARM_DECL nodes.
  1254.    This is done as part of starting the function.  */
  1255.  
  1256. static void
  1257. sdbout_reg_parms (parms)
  1258.      tree parms;
  1259. {
  1260.   while (parms)
  1261.     {
  1262.       if (GET_CODE (DECL_RTL (parms)) == REG
  1263.       && REGNO (DECL_RTL (parms)) >= 0
  1264.       && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
  1265.     {
  1266.       PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (parms)));
  1267.       PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
  1268.         PUT_SDB_SCL (C_REG);
  1269. #if defined( DSP56000 ) || defined( DSP96000 )
  1270.       PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
  1271. #else
  1272.       PUT_SDB_TYPE (plain_type (TREE_TYPE (parms), 0));
  1273. #endif
  1274.       PUT_SDB_ENDEF;
  1275.     }
  1276.       else if (GET_CODE (DECL_RTL (parms)) == MEM
  1277.            && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
  1278.            && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT)
  1279.     {
  1280.       int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
  1281.       /* A parm declared char is really passed as an int,
  1282.          so it occupies the least significant bytes.
  1283.          On a big-endian machine those are not the low-numbered ones.  */
  1284. #ifdef BYTES_BIG_ENDIAN
  1285.       if (TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
  1286.         offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
  1287.                - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
  1288. #endif
  1289.       if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset)
  1290.         {
  1291.           PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (parms)));          
  1292.           PUT_SDB_INT_VAL (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)));
  1293.           PUT_SDB_SCL (C_AUTO);
  1294.           PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
  1295.           PUT_SDB_ENDEF;
  1296.         }
  1297.     }
  1298.       parms = TREE_CHAIN (parms);
  1299.     }
  1300. }
  1301.  
  1302. /* Describe the beginning of an internal block within a function.
  1303.    Also output descriptions of variables defined in this block.
  1304.  
  1305.    N is the number of the block, by order of beginning, counting from 1,
  1306.    and not counting the outermost (function top-level) block.
  1307.    The blocks match the LET_STMTS in DECL_INITIAL (current_function_decl),
  1308.    if the count starts at 0 for the outermost one.  */
  1309.  
  1310. void
  1311. sdbout_begin_block (file, line, n)
  1312.      FILE *file;
  1313.      int line;
  1314.      int n;
  1315. {
  1316.   tree decl = current_function_decl;
  1317.   MAKE_LINE_SAFE (line);
  1318.   PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
  1319.   if (n == 1)
  1320.     {
  1321.       /* Include the outermost LET_STMT's variables in block 1.  */
  1322.       next_block_number = 0;
  1323.       do_block = 0;
  1324. #if defined( DSP56000 ) || defined( DSP96000 )
  1325.       sdbout_block (DECL_INITIAL (decl));
  1326. #else
  1327.       sdbout_block (DECL_INITIAL (decl), DECL_ARGUMENTS (decl));
  1328. #endif
  1329.     }
  1330.   next_block_number = 0;
  1331.   do_block = n;
  1332. #if defined( DSP56000 ) || defined( DSP96000 )
  1333.   sdbout_block (DECL_INITIAL (decl));
  1334. #else
  1335.   sdbout_block (DECL_INITIAL (decl), DECL_ARGUMENTS (decl));
  1336. #endif
  1337. }
  1338.  
  1339. /* Describe the end line-number of an internal block within a function.  */
  1340.      
  1341. void
  1342. sdbout_end_block (file, line)
  1343.      FILE *file;
  1344.      int line;
  1345. {
  1346.   MAKE_LINE_SAFE (line);
  1347.   PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
  1348. }
  1349.  
  1350. /* Output sdb info for the current function name.
  1351.    Called from assemble_function.  */
  1352.  
  1353. void
  1354. sdbout_mark_begin_function ()
  1355. {
  1356.   sdbout_symbol (current_function_decl, 0);
  1357. }
  1358.  
  1359. /* Called at beginning of function body (after prologue).
  1360.    Record the function's starting line number, so we can output
  1361.    relative line numbers for the other lines.
  1362.    Describe beginning of outermost block.
  1363.    Also describe the parameter list.  */
  1364.  
  1365. void
  1366. sdbout_begin_function (line)
  1367.      int line;
  1368. {
  1369.   sdb_begin_function_line = line - 1;
  1370.   PUT_SDB_FUNCTION_START (line);
  1371.   sdbout_parms (DECL_ARGUMENTS (current_function_decl));
  1372.   sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
  1373. }
  1374.  
  1375. /* Called at end of function (before epilogue).
  1376.    Describe end of outermost block.  */
  1377.  
  1378. void
  1379. sdbout_end_function (line)
  1380.      int line;
  1381. {
  1382.   MAKE_LINE_SAFE (line);
  1383.   PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
  1384.  
  1385.   /* Indicate we are between functions, for line-number output.  */
  1386.   sdb_begin_function_line = 0;
  1387. }
  1388.  
  1389. /* Output sdb info for the absolute end of a function.
  1390.    Called after the epilogue is output.  */
  1391.  
  1392. void
  1393. sdbout_end_epilogue ()
  1394. {
  1395.   char *name = IDENTIFIER_POINTER (DECL_NAME (current_function_decl));
  1396.   PUT_SDB_EPILOGUE_END (name);
  1397. }
  1398.  
  1399. #if defined( DSP56000 ) || defined( DSP56100 ) || defined( DSP96000 )
  1400. static int
  1401. push_derived_level ( dt_type, prev )
  1402.     int dt_type, prev;
  1403. {
  1404.     int result = ((((prev)&~N_BTMASK)<<N_TSHIFT)|(dt_type<<N_BTSHFT)|(prev&N_BTMASK));
  1405.     
  1406.     if ( 0xffff0000 & result )
  1407.     {
  1408.     /* if we have a type bigger than 16 bits, the assembler (and coff in 
  1409.        general) will not accept it. */
  1410.  
  1411.     warning( "derived type too big for coff: this will affect debugging only." );
  1412.     
  1413.     return prev;
  1414.     }
  1415.     return result;
  1416. }
  1417.  
  1418. put_sdb_def( decl )
  1419.     tree decl;
  1420. {
  1421.     fputs( "\t.def\t", asm_out_file);
  1422.  
  1423.     /* check to see if the "value was changed by the programmer using the
  1424.        god damn __asm construct */
  1425.     if ( GET_CODE( DECL_RTL( decl ) ) ==  MEM &&
  1426.      GET_CODE( XEXP( DECL_RTL( decl ), 0 ) ) == SYMBOL_REF )
  1427.     {
  1428.     assemble_name( asm_out_file, XSTR( XEXP( DECL_RTL( decl ), 0 ), 0 ) );
  1429.     }
  1430.     else
  1431.     ASM_OUTPUT_LABELREF( asm_out_file, IDENTIFIER_POINTER( DECL_NAME( decl ) ) );
  1432.  
  1433.     fputc( '\n', asm_out_file );
  1434. }
  1435. #endif
  1436. #endif /* SDB_DEBUGGING_INFO */
  1437.